﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Design;

namespace dialog_control
{
    public partial class DialogHeader : UserControl
    {
        private const int HeaderHeight        = 40;
        private const int UnderHeaderHeight   = 6;

        private const int HeaderFontSize      = 10;
        private const int DescriptionFontSize = 8;

        private Color HeaderColor = Color.FromArgb(255, 43, 87, 175);

        private const string HeaderFontName      = "Arial";
        private const string DescriptionFontName = "Arial";

        private string DialogHeaderText;
        private string DialogDescriptionText;

        private Bitmap Icon;

        public DialogHeader()
        {
            InitializeComponent();
        }

        public void SetHeaderText(string text)
        {
            DialogHeaderText = text;
        }

        public void SetDescriptionText(string text)
        {
            DialogDescriptionText = text;
        }

        public void SetIcon(Bitmap icon)
        {
           Icon = icon;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Bitmap btm = new Bitmap(Width, Height);
            Graphics graph = Graphics.FromImage(btm);            

            using (Brush headerBrush = new SolidBrush(HeaderColor))
            {
                graph.FillRectangle(headerBrush, 0, 0, btm.Width, HeaderHeight);
            }

            if (DialogHeaderText != null && DialogHeaderText.Length != 0)
            {
              graph.DrawString(DialogHeaderText, new Font(HeaderFontName, HeaderFontSize, FontStyle.Bold),
                Brushes.White, new PointF(Icon != null ? 10 + Icon.Width : 10, HeaderHeight / 2 - HeaderFontSize - 5));
            }            

            if (DialogDescriptionText != null && DialogDescriptionText.Length != 0)
            {
              graph.DrawString(DialogDescriptionText, new Font(DescriptionFontName, DescriptionFontSize, FontStyle.Italic),
                Brushes.White, new PointF(Icon != null ? 10 + Icon.Width : 10, HeaderHeight / 2));
            }            

            if (Icon != null)
            {
              graph.DrawImage(Icon, new Point(5, 5));
            }

            e.Graphics.DrawImageUnscaled(btm, 0, 0, Width, Height);
        }
    }
}